<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="条形码" prop="barCode">
        <el-input v-model="queryParams.barCode" placeholder="请输入条形码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="资产编号" prop="assetNo">
        <el-input v-model="queryParams.assetNo" placeholder="请输入资产编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="类型" prop="typeCode">
        <el-select v-model="queryParams.typeCode" placeholder="请选择类型" clearable>
          <el-option v-for="dict in dict.type.ts_type_code" :key="dict.value" :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="型号" prop="modelCode">
        <el-input v-model="queryParams.modelCode" placeholder="请输入型号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="接线方式" prop="wiringMode">
        <el-input v-model="queryParams.wiringMode" placeholder="请输入接线方式" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="mdItList" @selection-change="handleSelectionChange">
      <el-table-column label="互感器标识" align="center" prop="itId" min-width="90px" />
      <el-table-column label="产权单位" align="center" prop="prOrg" />
      <el-table-column label="所在单位" align="center" prop="belongDept" />
      <el-table-column label="合同标识" align="center" prop="contractId" v-if="false" />
      <el-table-column label="接收标识" align="center" prop="rcvId" v-if="false" />
      <el-table-column label="生产批次" align="center" prop="lotNo" />
      <el-table-column label="条形码" align="center" prop="barCode" />
      <el-table-column label="资产编号" align="center" prop="assetNo" />
      <el-table-column label="出厂编号" align="center" prop="madeNo" />
      <el-table-column label="类别" align="center" prop="sortCode" />
      <el-table-column label="类型" align="center" prop="typeCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ts_type_code" :value="scope.row.typeCode" />
        </template>
      </el-table-column>
      <el-table-column label="型号" align="center" prop="modelCode" />
      <el-table-column label="原理" align="center" prop="measPrincipleCode" />
      <el-table-column label="绝缘方式" align="center" prop="insulationMode" />
      <el-table-column label="绕组配置" align="center" prop="windingConfigCode" />
      <el-table-column label="制造单位" align="center" prop="manufacturer" />
      <el-table-column label="出厂日期" align="center" prop="madeDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.madeDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="额定电压" align="center" prop="rvCode" />
      <el-table-column label="额定频率" align="center" prop="ratedFreqCode" />
      <el-table-column label="功率因数" align="center" prop="pf" />
      <el-table-column label="容量" align="center" prop="cap" />
      <el-table-column label="额定电流变比" align="center" prop="rcRatioCode" min-width="100px" />
      <el-table-column label="额定二次电流" align="center" prop="sndRvCode" min-width="100px" />
      <el-table-column label="额定一次电流" align="center" prop="fstRcCode" min-width="100px" />
      <el-table-column label="TA额定二次负荷" align="center" prop="taRatedSndLoad" min-width="120px" />
      <el-table-column label="TA轻载负荷" align="center" prop="taLightLoad" min-width="90px" />
      <el-table-column label="TA准确度等级" align="center" prop="taPreCode" min-width="110px" />
      <el-table-column label="TA匝数" align="center" prop="taTurns" />
      <el-table-column label="电压变比" align="center" prop="voltRatioCode" />
      <el-table-column label="设备单价" align="center" prop="eqipPrc" />
      <el-table-column label="建档人" align="center" prop="docCreatorNo" />
      <el-table-column label="建档日期" align="center" prop="docCreateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.docCreateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="校验日期" align="center" prop="chkDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.chkDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="轮换周期" align="center" prop="rotateCycle" />
      <el-table-column label="报废原因" align="center" prop="discardReason" />
      <el-table-column label="报废日期" align="center" prop="descardDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.descardDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="产权" align="center" prop="prCode" />
      <el-table-column label="新表标识" align="center" prop="newFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ts_new_flag" :value="scope.row.newFlag" />
        </template>
      </el-table-column>
      <el-table-column label="物料号" align="center" prop="erpBatchNo" />
      <el-table-column label="当前状态" align="center" prop="curStatusCode" />
      <el-table-column label="库房名称" align="center" prop="whName" min-width="120px" />
      <el-table-column label="库区名称" align="center" prop="whAreaname" />
      <el-table-column label="存放区名称" align="center" prop="storeAreaName" min-width="120px" />
      <el-table-column label="储位名称" align="center" prop="storeLocName" />
      <el-table-column label="箱条形码" align="center" prop="boxBarCode" min-width="90px" />
      <el-table-column label="接线方式" align="center" prop="wiringMode" />
      <el-table-column label="写入时间" align="center" prop="writeDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.writeDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理标记" align="center" prop="handleFlag" />
      <el-table-column label="处理时间" align="center" prop="handleDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.handleDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" min-width="150px">
        <template slot-scope="scope">
          <el-button size="small" type="primary" @click="taskDetails(scope.row)">互感器资产信息详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改互感器资产信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1300px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="产权单位" prop="prOrg">
              <span>{{ form.prOrg }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所在单位" prop="belongDept">
              <span>{{ form.belongDept }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同标识" prop="contractId" v-if="false">
              <el-input v-model="form.contractId" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="处理时间" prop="handleDate">
              <span>{{ form.handleDate }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="接收标识" prop="rcvId" v-if="false">
              <span>{{ form.rcvId }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="写入时间" prop="writeDate">
              <span>{{ form.writeDate }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产批次" prop="lotNo">
              <span>{{ form.lotNo }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="条形码" prop="barCode">
              <span>{{ form.barCode }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="资产编号" prop="assetNo">
              <span>{{ form.assetNo }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出厂编号" prop="madeNo">
              <span>{{ form.madeNo }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="类别" prop="sortCode">
              <span>{{ form.sortCode }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="类型" prop="category">
              <span>{{ category }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="型号" prop="modelCode">
              <span>{{ form.modelCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="原理" prop="measPrincipleCode">
              <span>{{ form.measPrincipleCode }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="绝缘方式" prop="insulationMode">
              <span>{{ form.insulationMode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="绕组配置" prop="windingConfigCode">
              <span>{{ form.windingConfigCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="制造单位" prop="manufacturer">
              <span>{{ form.manufacturer }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="出厂日期" prop="madeDate">
              <span>{{ form.madeDate }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="额定电压" prop="rvCode">
              <span>{{ form.rvCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="额定频率" prop="ratedFreqCode">
              <span>{{ form.ratedFreqCode }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="功率因数" prop="pf">
              <span>{{ form.pf }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="容量" prop="cap">
              <span>{{ form.cap }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="额定电流变比" prop="rcRatioCode">
              <span>{{ form.rcRatioCode }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="额定二次电流" prop="sndRvCode">
              <span>{{ form.sndRvCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="额定一次电流" prop="fstRcCode">
              <span>{{ form.fstRcCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="TA额定二次负荷" prop="taRatedSndLoad">
              <span>{{ form.taRatedSndLoad }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="TA轻载负荷" prop="taLightLoad">
              <span>{{ form.taLightLoad }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="TA准确度等级" prop="taPreCode">
              <span>{{ form.taPreCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="TA匝数" prop="taTurns">
              <span>{{ form.taTurns }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="电压变比" prop="voltRatioCode">
              <span>{{ form.voltRatioCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备单价" prop="eqipPrc">
              <span>{{ form.eqipPrc }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="建档人" prop="docCreatorNo">
              <span>{{ form.docCreatorNo }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="建档日期" prop="docCreateDate">
              <span>{{ form.docCreateDate }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="校验日期" prop="chkDate">
              <span>{{ form.chkDate }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="轮换周期" prop="rotateCycle">
              <span>{{ form.rotateCycle }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="报废原因" prop="discardReason">
              <span>{{ form.discardReason }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报废日期" prop="descardDate">
              <span>{{ form.descardDate }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产权" prop="prCode">
              <span>{{ form.prCode }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="新表标识" prop="word">
              <span>{{ word }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物料号" prop="erpBatchNo">
              <span>{{ form.erpBatchNo }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="当前状态" prop="curStatusCode">
              <span>{{ form.curStatusCode }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="库房名称" prop="whName">
              <span>{{ form.whName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="库区名称" prop="whAreaname">
              <span>{{ form.whAreaname }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="存放区名称" prop="storeAreaName">
              <span>{{ form.storeAreaName }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="储位名称" prop="storeLocName">
              <span>{{ form.storeLocName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="箱条形码" prop="boxBarCode">
              <span>{{ form.boxBarCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="接线方式" prop="wiringMode">
              <span>{{ form.wiringMode }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="处理标记" prop="handleFlag">
              <span>{{ form.handleFlag }}</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMdIt, getMdIt, } from "@/api/storage/mdIt";

export default {
  name: "MdIt",
  dicts: ["ts_type_code", "ts_new_flag"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 互感器资产信息表格数据
      mdItList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        barCode: null,
        assetNo: null,
        typeCode: null,
        modelCode: null,
        wiringMode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      word: "",
      category: ""
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询互感器资产信息列表 */
    getList() {
      this.loading = true;
      listMdIt(this.queryParams).then(response => {
        this.mdItList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 返回按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        itId: null,
        prOrg: null,
        belongDept: null,
        contractId: null,
        rcvId: null,
        lotNo: null,
        barCode: null,
        assetNo: null,
        madeNo: null,
        sortCode: null,
        typeCode: null,
        modelCode: null,
        measPrincipleCode: null,
        insulationMode: null,
        windingConfigCode: null,
        manufacturer: null,
        madeDate: null,
        rvCode: null,
        ratedFreqCode: null,
        pf: null,
        cap: null,
        rcRatioCode: null,
        sndRvCode: null,
        fstRcCode: null,
        taRatedSndLoad: null,
        taLightLoad: null,
        taPreCode: null,
        taTurns: null,
        voltRatioCode: null,
        eqipPrc: null,
        docCreatorNo: null,
        docCreateDate: null,
        chkDate: null,
        rotateCycle: null,
        discardReason: null,
        descardDate: null,
        prCode: null,
        newFlag: null,
        erpBatchNo: null,
        curStatusCode: null,
        whId: null,
        whAreaId: null,
        storeAreaId: null,
        storeLocId: null,
        boxBarCode: null,
        wiringMode: null,
        writeDate: null,
        handleFlag: null,
        handleDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.itId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 互感器资产信息详情 */
    taskDetails(row) {
      const itId = row.itId
      getMdIt(itId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "互感器资产信息详情";
        if (this.form.newFlag == "01") {
          this.word = "是"
        } else if (this.form.newFlag == "02") {
          this.word = "否"
        }
        if (this.form.typeCode == "01") {
          this.category = "干式"
        } else if (this.form.typeCode == "02") {
          this.category = "浇注式"
        } else if (this.form.typeCode == "03") {
          this.category = "油浸式"
        }
      });
    },
  }
};
</script>
